package com.logistic.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.logistic.dao.RecordDao;
import com.logistic.dao.UserDao;
import com.logistic.domain.Record;
import com.logistic.service.RecordService;


@Service
public class RecordServiceImpl implements RecordService {

	@Autowired
	private RecordDao recordDao;
	private UserDao userDao;
	
	/**
	 * 查询所有记录
	 * @param sort 排序字段
	 * @return
	 */
	public List findRecordAll(String sort) {
		
		List list = new ArrayList();
		list = recordDao.getAll();
		return list;
	}
	
	/**
	 * 保存
	 */
	public String save(Record record) {
		Calendar day = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		String times_num = sdf.format(day.getTime());
		
		record.setId(times_num);
		int num = recordDao.save(record);
		if(num > 0) {
			return "ok";
		} else {
			return "error";
		}
		
	}
	
	/**
	 * 修改
	 */
	public String modify(Record record) {
		
		recordDao.modify(record);
		return "ok";
	}
	
	/**
	 * 根据xh删除Record
	 * @return
	 */
	public void deleteByIdStr(String idStr) {
		String[] ids = idStr.split("'"); 
		for(int i = 0; i < ids.length; i++) {
			recordDao.delete(ids[i]);
		}
	}

	public RecordDao getRecordDao() {
		return recordDao;
	}

	public void setRecordDao(RecordDao recordDao) {
		this.recordDao = recordDao;
	}

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

}
